import request from '@/utils/request'
import type { CartResponse, CartUpdateParams } from '@/types/cart'

export const cartAPI = {
    // 获取购物车列表
    getCartList(): Promise<CartResponse> {
        return request.get('/user/cart/list')
    },

    // 添加图书到购物车
    addToCart(bookId: number) {
        return request.post(`/user/cart/add/${bookId}`)
    },

    // 修改购物车数量
    updateCart(params: CartUpdateParams) {
        return request.put('/user/cart/update', params)
    },

    // 删除购物车项
    deleteCartItem(bookId: number) {
        return request.delete(`/user/cart/delete/${bookId}`)
    },

    // 结算购物车
    checkout(cartId?: number) {
        const url = cartId ? `/user/cart/insert/${cartId}` : '/user/cart/insert'
        return request.post(url)
    }
}
